package inits

import (
	"context"
	"github.com/go-redis/redis/v8"
	"good/config"
	"good/global"
	"log"
)

func InitRedis() {
	ctx := context.Background()
	AppConf := config.AppConf.Redis
	global.Rdb = redis.NewClient(&redis.Options{
		Addr:     AppConf.Addr,     // use default Addr
		Password: AppConf.Password, // no password set
		DB:       AppConf.Db,       // use default DB
	})

	err := global.Rdb.Ping(ctx).Err()
	if err != nil {
		panic("redis 连接失败")
	}
	log.Println("redis 连接成功", global.Rdb)
}
